package com.example.model;

import java.io.Serializable;

public class TetrisPath implements Cloneable, Serializable {
    public int blockType;//形态

    public int turnState;//旋转状态
    public int offsetX;//偏移向量
    public int offsetY;//偏移向量
    public int blockCount;//下落数量
    public boolean isFirstCount;
    public TetrisPath(){

    }

    public TetrisPath(int blockType, int turnState, int offsetX, int offsetY, int blockCount,boolean isFirstCount) {
        this.blockType = blockType;
        this.turnState = turnState;
        this.offsetX = offsetX;
        this.offsetY = offsetY;
        this.blockCount = blockCount;
        this.isFirstCount=isFirstCount;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
//        sb.append("isFirstCount:"+isFirstCount);
//        sb.append("\n");
//        sb.append("turnState:"+turnState);
//        sb.append("\n");
//        sb.append("oldTurnState:"+(blockCount)%4);
//        sb.append("\n");




        //偏移
        if(offsetX==0){
            //下移
            if(offsetY ==0){
                sb.append("this.game.tetris.drop();");
                sb.append("\n");
                sb.append("this.game.playStep('down', 0);");
                sb.append("\n");
                sb.append("this.game.opts.onDrop();");
                sb.append("\n");
                sb.append("//tetrisNode.quickDown();");
                sb.append("\n");
                sb.append("//tetrisNode.down();");
                sb.append("\n");
            }else{

//                sb.append("this.game.tetris.drop();");
//                sb.append("\n");
//                sb.append("this.game.playStep('down', 0);");
//                sb.append("\n");
//                sb.append("this.game.opts.onDrop();");
//                sb.append("\n");
                if(offsetY == 1){
                    sb.append(String.format("this.game.playStep('down', %d , false);",offsetY));
                }else {
                    sb.append(String.format("this.game.playStep('down', %d , false);",offsetY+2));
                }

                sb.append("\n");
                sb.append(String.format("//tetrisNode.down(%d);",(offsetY)));
                sb.append("\n");
            }

        }else if(offsetX >0){
            //旋转单独处理
            if(offsetX >999 && offsetY >999){
                sb.append("this.game.tetris.rotate();");
                sb.append("\n");
                sb.append("//tetrisNode.turn();");
                sb.append("\n");
            }else{
                //右移
                sb.append(String.format("this.game.playStep('right', %d, false);",offsetX));
                sb.append("\n");
                sb.append(String.format("//tetrisNode.right(%d);",offsetX));
                sb.append("\n");
            }
        }else{
            //左移
            sb.append(String.format("this.game.playStep('left', %d, false);",-offsetX));
            sb.append("\n");
            sb.append(String.format("//tetrisNode.left(%d);",-offsetX));
            sb.append("\n");
        }
        return sb.toString();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        TetrisPath node = null;
        try{
            node = (TetrisPath)super.clone();
        }catch(CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return node;
    }
}
